package com.garrett.demo.sys.dao;

import com.garrett.demo.sys.entity.Account;
import com.garrett.demo.sys.entity.SimsStudent;
import com.garrett.demo.sys.entity.UserInfo;

public class UserDataBaseDemo implements UserDao {
    private Account onlyAccount = new Account("1", "admin", "admin");
    private UserInfo onlyUser = new UserInfo("1", "学号(212006358)", "张书伟");

    public UserInfo getUserByID(String id) {
        if (onlyUser.getId().equals(id)) {
            return onlyUser;
        }
        return null;
    }

    public Account queryAccount(String account) {
        if (onlyAccount.getAccount().equals(account)) {
            return onlyAccount;
        }
        return null;
    }

    private Account only = new Account("212006358", "admin", "admin");
    private SimsStudent[] students = new SimsStudent[3];
    private Account[] accounts = new Account[3];

    public UserDataBaseDemo() {
        this.accounts[0] = only;
         SimsStudent student = new SimsStudent();
        student.setStudentId(only.getId());
        student.setStudentName("admin");
        this.students[0] = student;
    }


    public int addAccount(Account account) {
        for (int i = 0; i < accounts.length; i++) {
            if (accounts[i] == null) {
                accounts[i] = account;
                return 1;
            }
        }
        return 0;
    }

    @Override
    public int delAccountById(String id) {
        return 0;
    }

    @Override
    public int modifyAccount(Account account) {
        return 0;
    }

    public int createUser(SimsStudent userInfo) {
        for (int i = 0; i < students.length; i++) {
            if (students[i] == null) {
                students[i] = userInfo;
                return 1;
            }
        }
        return 0;
    }

    @Override
    public int delStudentInfo(String stuId) {
        return 0;
    }

    @Override
    public int modifyStudentInfo(SimsStudent student) {
        return 0;
    }

    @Override
    public void reWrite() {

    }

    public SimsStudent getStudentById(String stuId) {
        for (int i = 0; i < students.length; i++)
            if (stuId.equals(students[i].getStudentId())) {
                return students[i];
            }
        return null;
    }

    public Account getUserByAccount(String account) {

        for (int i = 0; i < accounts.length; i++) {
            if (account.equals(accounts[i].getAccount())) {
                return accounts[i];
            }
        }
        return null;
    }

    @Override
    public SimsStudent[] getAllStudent() {
        return students;
    }

    @Override
    public Account[] getAllAccounts() {
        return accounts;
    }
}